
const AuthManager = {
	getToken() {
		return sessionStorage.token;
	},
	setToken(token) {
    sessionStorage.token = token;
	},
	loggedIn: function () {
		return !!sessionStorage.token;
	},
	login(email, pass, callback) {
		callback = arguments[arguments.length - 1]
		if (sessionStorage.token) {
			if (callback) callback(true)
			return
		}
		pretendRequest(email, pass, (res) => {
			if (res.authenticated) {
        sessionStorage.token = res.token
				if (cb) cb(true)
				this.onChange(true)
			} else {
				if (cb) cb(false)
				this.onChange(false)
			}
		})
	},
	logout() {
		delete sessionStorage.token;
	},
}

export default AuthManager;
